home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / src / ChunkyStartup2.lha / ChunkyStartup2K1 / KZoomSprite.i < prev    next >
Text File  |  2001-04-16  |  12KB  |  433 lines

  1. ;    /+===========================================================+/
  2. ;   //                                                           //
  3. ;  //           Modulo-free 8bit Zoom Sprite                    //
  4. ; //                                                           //
  5. ;/+===========================================================+/
  6. ; KZoomSprite.i
  7. ; ->krabob@online.fr<- (Vic Ferry) 01-02-2001
  8. ; This routines support free-resolution screens+
  9. ; free-resolution texture+
  10. ; free rectangle clipping+
  11. ; coordinate-exchange.
  12. ; 16 bit shifted- fixed comas UV coordinates.
  13. ;
  14. ; phxass command line to make a .o:
  15. ;  phxass KZoomSprite.i I=include: M=68020
  16.  
  17.     ; all macros needed to create some structures.
  18.  incdir include:
  19.     include exec/types.i
  20.  
  21.  
  22.  STRUCTURE ScreenRenderContext,0
  23.  
  24.         APTR src_ChunkyScreen
  25.         LONG src_BytesModulo
  26.         LONG src_ClipX1
  27.         LONG src_ClipY1
  28.         LONG src_ClipX2
  29.         LONG src_ClipY2
  30.  
  31.  LABEL  src_SIZEOF
  32.  
  33.  STRUCTURE TextureContext,0
  34.  
  35.         APTR ttc_ChunkyTexture
  36.         LONG ttc_BytesModulo
  37.         LONG ttc_U1                     ;<<16
  38.         LONG ttc_V1                     ;<<16
  39.         LONG ttc_U2                     ;<<16
  40.         LONG ttc_V2                     ;<<16
  41.  
  42.  LABEL  ttc_SIZEOF
  43.  
  44. ;Following instructions -    fmul.s fp0,fp1
  45. ;                move.l d0,d2
  46. ;                move.l d1,d3
  47. ;                move.l d2,d4
  48. ;                add.l d5,d6
  49. ;                add.l d0,d1 - executes in 3 cycles !!!
  50.  
  51. ; d0.l x1 Rectangle to fit on Chunky Screen.
  52. ; d1.l y1 
  53. ; d2.l x2
  54. ; d3.l y2
  55.  
  56. ; a0.l Screen Render Context (Pointer)
  57. ; a1.l TextureContext (Pointer)
  58.  
  59.         XDEF    KZoomSprite8bit68K
  60.         XDEF    _KZoomSprite8bit68K
  61.  
  62.                 section ZoomSprite,code
  63.  
  64. KZoomSprite8bit68K
  65. _KZoomSprite8bit68K
  66.         movem.l d0-d7/a0-a6,-(sp)
  67.  
  68. ; a2 kept for evt. table.
  69.  
  70. ;  +---------------------------------------------+
  71. ; /             Prepare Height vectors          /
  72. ;+---------------------------------------------+
  73.  
  74.         move.l  d0,a4   ;X1,X2 kept
  75.         move.l  d2,a5
  76.  
  77.         ;  +-------------------------------------+
  78.         ; /     Swap if order Y is not right    /
  79.         ;+-------------------------------------+
  80.         ;d1 Y1
  81.         ;d3 Y2
  82.         move.l  ttc_V1(a1),d5   ;V1
  83.         move.l  ttc_V2(a1),d6   ;V2
  84.  
  85.         cmp.l   d3,d1
  86.         beq     .end            ; exit if 0 lines
  87.         blt     .noswapY
  88.         
  89.                 ; if Y1>Y2 swap values
  90.  
  91.                 move.l  d1,d7
  92.                 move.l  d3,d1
  93.                 move.l  d7,d3
  94.  
  95.                 move.l  d5,d7
  96.                 move.l  d6,d5
  97.                 move.l  d7,d6
  98.  
  99.                 sub.l   #65536,d5   ;last pixel ->first is out (sub logic)
  100.                 sub.l   #65536,d6
  101. .noswapY
  102.  
  103. ; Here:
  104. ; d0: -
  105. ; d1: Y1
  106. ; d2: -
  107. ; d3: Y2
  108. ; d4: -
  109. ; d5: V1
  110. ; d6: V2
  111. ; d7:   -usually calculation-
  112.  
  113. ; a0: RC
  114. ; a1: TXTC
  115. ; a2: kept for table
  116. ; a3: (will be chunky ptr)
  117. ; a4: X1
  118. ; a5: X2
  119.         ;  +-------------------------------------+
  120.         ; /     Clip Up                         /
  121.         ;+-------------------------------------+
  122.  
  123.         move.l  src_ClipY1(a0),d4
  124.         cmp.l   d4,d3
  125.         ble     .end                    ;if out up, exit
  126.         
  127.         cmp.l   d1,d4                   ; have to be clipped or not ?
  128.         ble     .noclip_up              ; >0 had to be clipped
  129.  
  130.                 ;d5= V1 = ...
  131.                 ; a=(d4-d1) (>0)
  132.                 ; b=(d3-d1) (>0)
  133.                 ;Ub=(d6-d5)
  134.                 ;Ua=(Ub/b)*a
  135.                 ;d5 = d5(V1) + Ua
  136.  
  137.                 
  138.                 ;060: scramble these 3*2...
  139.                 move.l  d4,d0   
  140.                 sub.l   d1,d0   ;d0=a (pixel.l)
  141.  
  142.                 move.l  d3,d2           
  143.                 sub.l   d1,d2   ;d2=b (pixel.l)
  144.                 
  145.                 move.l  d6,d7   
  146.                 sub.l   d5,d7   ;d7.l=Ub<<16 (-+)
  147.  
  148.  
  149.                 divs.l  d2,d7   ;Ub/b   divs first because <<16
  150.                 muls.l  d0,d7   ;Ub/b*a
  151.                 
  152.                 add.l   d7,d5   ;V1 Clipped
  153.                 
  154.                 ;d1= Y1=ClipY1          
  155.                 move.l  d4,d1
  156. .noclip_up
  157.         ;  +-------------------------------------+
  158.         ; /     Clip Down                       /
  159.         ;+-------------------------------------+
  160.  
  161.         move.l  src_ClipY2(a0),d4
  162.         cmp.l   d4,d1
  163.         bge     .end                    ;if out down, exit
  164.  
  165.         cmp.l   d3,d4
  166.         bge     .noclip_down
  167.  
  168.                 move.l  d3,d0
  169.                 sub.l   d4,d0   ;d0=a
  170.  
  171.                 move.l  d3,d2
  172.                 sub.l   d1,d2   ;d2=b
  173.  
  174.                 move.l  d6,d7
  175.                 sub.l   d5,d7   ;Ub
  176.  
  177.                 divs.l  d2,d7
  178.                 muls.l  d0,d7   ;a
  179.  
  180.                 sub.l   d7,d6   ;V2-a ... V2 Clipped
  181.  
  182.                 ;d3=ClipY2
  183.                 move.l  d4,d3
  184. .noclip_down
  185.         ;  +-----------------------------------------------------+
  186.         ; /     Set Screen Pointer to Y line & find vector      /
  187.         ;+-----------------------------------------------------+
  188.  
  189.         sub.l   d1,d3           ;d3=Height to render.
  190.  
  191.         sub.l   d5,d6           ;(V2-V1)<<16
  192.         divs.l  d3,d6           ;texture Height vector
  193.         subq.l  #1,d3           ;to use with dbf.w
  194.  
  195.  
  196.         move.l  src_ChunkyScreen(a0),a3
  197.         move.l  src_BytesModulo(a0),d0
  198.         mulu.l  d0,d1           
  199.         add.l   d1,a3           ;a3 point the line to render.
  200.         ;d1 is freed.
  201.  
  202.         
  203.  
  204.  
  205. ;  +---------------------------------------------+
  206. ; /             Prepare Width vectors           /
  207. ;+---------------------------------------------+
  208.  
  209.         move.l  a4,a6
  210.         move.l  a5,d1
  211.  
  212.         move.l  d5,a4
  213.         move.l  d6,a5
  214.  
  215.  
  216. ; Here:
  217. ; d0: -
  218. ; d1: X2
  219. ; d2: -
  220. ; d3: Y lenght to render.
  221. ; d4: -Clip
  222. ; d5: -U1
  223. ; d6: -U2
  224. ; d7: -
  225.  
  226. ; a0: RC
  227. ; a1: TXTC
  228. ; a2: Kept for table
  229. ; a3: Chunky ptr
  230. ; a4: V Start <<16
  231. ; a5: V Vector <<16
  232. ; a6: X1
  233.  
  234.         ;  +-------------------------------------+
  235.         ; /     Swap if order X is not right    /
  236.         ;+-------------------------------------+
  237.         ;d0 X1
  238.         ;d1 X2
  239.  
  240.         move.l  ttc_U1(a1),d5   ;U1
  241.         move.l  ttc_U2(a1),d6   ;U2
  242.  
  243.         cmp.l   d1,a6
  244.         beq     .end            ; exit if 0 lines
  245.         blt     .noswapX
  246.         
  247.                 ; if X1>X2 swap values
  248.  
  249.                 move.l  a6,d7
  250.                 move.l  d1,a6
  251.                 move.l  d7,d1
  252.  
  253.                 move.l  d5,d7
  254.                 move.l  d6,d5
  255.                 move.l  d7,d6
  256.  
  257.                 sub.l   #65536,d5   ;last pixel ->first is out (sub logic)
  258.                 sub.l   #65536,d6
  259. .noswapX
  260.  
  261.         ;  +-------------------------------------+
  262.         ; /     Clip Left                       /
  263.         ;+-------------------------------------+
  264.  
  265.         move.l  src_ClipX1(a0),d4
  266.         cmp.l   d4,d1
  267.         ble     .end                    ;if out up, exit
  268.         
  269.         cmp.l   a6,d4                   ; have to be clipped or not ?
  270.         ble     .noclip_left            ; >0 had to be clipped
  271.  
  272.                 ;d5= V1 = ...
  273.                 ; a=(d4-a6) (>0)
  274.                 ; b=(d1-a6) (>0)
  275.                 ;Ub=(d6-d5)
  276.                 ;Ua=(Ub/b)*a
  277.                 ;d5 = d5(U1) + Ua
  278.  
  279.                 
  280.                 ;060: scramble these 3*2...
  281.                 move.l  d4,d0
  282.                 sub.l   a6,d0   ;d0=a (pixel.l)
  283.  
  284.                 move.l  d1,d2
  285.                 sub.l   a6,d2   ;d2=b (pixel.l)
  286.                 
  287.                 move.l  d6,d7
  288.                 sub.l   d5,d7   ;d7.l=Ub<<16 (-+)
  289.  
  290.  
  291.                 divs.l  d2,d7   ;Ub/b   divs first because <<16
  292.                 muls.l  d0,d7   ;Ub/b*a
  293.                 
  294.                 add.l   d7,d5   ;U1 Clipped
  295.                 
  296.                 ;a6= Y1=ClipY1          
  297.                 move.l  d4,a6
  298. .noclip_left
  299.         ;  +-------------------------------------+
  300.         ; /     Clip Right                      /
  301.         ;+-------------------------------------+
  302.  
  303.         move.l  src_ClipX2(a0),d4
  304.         cmp.l   d4,a6
  305.         bge     .end                    ;if out down, exit
  306.  
  307.         cmp.l   d1,d4
  308.         bge     .noclip_right
  309.  
  310.                 move.l  d1,d0
  311.                 sub.l   d4,d0   ;d0=a
  312.  
  313.                 move.l  d1,d2
  314.                 sub.l   a6,d2   ;d2=b
  315.  
  316.                 move.l  d6,d7
  317.                 sub.l   d5,d7   ;Ub
  318.  
  319.                 divs.l  d2,d7
  320.                 muls.l  d0,d7   ;a
  321.  
  322.                 sub.l   d7,d6   ;V2-a ... V2 Clipped
  323.  
  324.                 ;d1=ClipY2
  325.                 move.l  d4,d1
  326. .noclip_right
  327.  
  328.  
  329.         ;  +-----------------------------------------------------+
  330.         ; /     Set Screen Pointer to X pixel & find vector     /
  331.         ;+-----------------------------------------------------+
  332.  
  333.  
  334.         add.l   a6,a3   ;chunky start x,Y first pixel
  335.         sub.l   a6,d1   ;X2-X1 >0 d1=nb of pixel in width.
  336.  
  337.         sub.l   d5,d6   ;U delta <<16
  338.         divs.l  d1,d6   ;texture Width vector
  339.         swap    d5      ; addx trick for U vect
  340.         swap    d6      
  341.  
  342.         move.l  src_BytesModulo(a0),d0
  343.         sub.l   d1,d0
  344.  
  345.  
  346.         subq.l  #1,d1   ;d1 original width length for loop - a6 freed
  347.  
  348.  
  349.         move.l  ttc_ChunkyTexture(a1),a0        ;no more need for RC.
  350.         move.l  ttc_BytesModulo(a1),a1  
  351.  
  352. ; Here:
  353. ; d0: screen modulo - drawn width
  354. ; d1: X length to render(orig)
  355. ; d2: X length to render(dbf).
  356. ; d3: Y lenght to render.
  357. ; d4: - (things)
  358. ; d5: -U Start <<16     swaped(orig)
  359. ; d6: -U Vector <<16    swaped
  360. ; d7: -U Start <<16     swaped(scan)
  361.  
  362.  
  363. ; a0: Chunky Texture Start.
  364. ; a1: Texture modulo
  365. ; a2: Kept for table
  366. ; a3: Chunky ptr of line.
  367. ; a4: V Start <<16
  368. ; a5: V Vector <<16
  369. ; a6: Chunky Texture "at the line"
  370.  
  371.  
  372. ;  +---------------------------------------------+
  373. ; /     Height Loop                             /
  374. ;+---------------------------------------------+
  375. .loop_height
  376.                 ; find line on texture -> a6
  377.                 move.l  a0,a6
  378.                 move.l  a4,d4   ;V<<16
  379.                 swap    d4      ;V.w
  380.  
  381.                 move.l  a1,d7   ;texture modulo
  382.                 muls.w  d7,d4   ;d4.l= V*txtmodulo
  383.                 add.l   d4,a6           
  384.                                 
  385.                 ; reset U scan
  386.                 move.l  d5,d7           
  387. ;;;;;;;;;;      add.l   #0,d7   ;set "x" to 0. was optimlized by phxass.
  388.                 andi    #$00f,ccr
  389.                 
  390.  
  391.                 ; reset width loop.
  392.                 move.w  d1,d2           
  393. ;  +---------------------------------------------+
  394. ; /             Width Loop                      /
  395. ;+---------------------------------------------+
  396. .loop_width
  397.                 
  398.                         move.b  (a6,d7.w),d4
  399.                         beq.b   .noprint
  400.                         move.b  d4,(a3)
  401. .noprint
  402.                         addx.l  d6,d7   ;U vector
  403.                         addq.l  #1,a3   ;miraculously doesnt reset "x".
  404.  
  405.                 dbf.w   d2,.loop_width
  406. ;  +---------------------------------------------+
  407. ; /             End Width Loop                  /
  408. ;+---------------------------------------------+
  409.  
  410.                 add.l   d0,a3   ; + rest of lines
  411.  
  412.                 ;+ V vector
  413.                 add.l   a5,a4
  414.  
  415.         dbf.w   d3,.loop_height
  416. ;  +---------------------------------------------+
  417. ; /     End of Height Loop                      /
  418. ;+---------------------------------------------+
  419. .end:
  420.         movem.l (sp)+,d0-d7/a0-a6
  421.         rts
  422. ;    /+===========================================================+/
  423. ;   //                                                           //
  424. ;  //                   End                                     //
  425. ; //                                                           //
  426. ;/+===========================================================+/
  427.  
  428.  
  429.  
  430.  
  431.  
  432.